package com.cy.member;

import java.awt.Point;
import java.util.ArrayList;

import com.cy.member.parent.ChineseChessman;
/**
 * 马
 * @author CY
 */
public class Ma extends ChineseChessman {

	/**
	 * @param who true红色，false黑色
	 */
	public Ma(boolean who) {
		if(who) {//红车
			this.setBackground("image/红马.GIF");
		} else {//黑车
			this.setBackground("image/黑马.gif");
		}
		//生成棋子
		this.generateChessman(who);
	}

	/**
	 * 马的移动策略
	 * 马是日字移动，分为2种一种是竖马，一种是横马
	 * 然后在判断是否有逼马腿。
	 */
	@Override
	public boolean move(Point site, ArrayList<Point> points) {
		//起点坐标
		Point origin = getChessman().getSite();
		//竖马
		if(Math.abs(origin.x - site.x) == 1 && Math.abs(origin.y - site.y) == 2) {
			//逼马腿
			if(origin.y > site.y && points.contains(new Point(origin.x,origin.y-1))) {
				return false;
			} else if (origin.y < site.y && points.contains(new Point(origin.x,origin.y+1))) {
				return false;
			}
			getChessman().setSite(site);
			return true;
		} else if(Math.abs(origin.x - site.x) == 2 && Math.abs(origin.y - site.y) == 1) {//横马
			if(origin.x > site.x && points.contains(new Point(origin.x-1,origin.y))) {
				return false;
			} else if (origin.x < site.x && points.contains(new Point(origin.x+1,origin.y))) {
				return false;
			}
			getChessman().setSite(site);
			return true;
		} else {//没有走日
			return false;
		}
	}

}
